feat: support server-only and client-only modules (#2162)#2167
Conversation
✅ Deploy Preview for solid-start-landing-page ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
🦋 Changeset detectedLatest commit: 390bce3 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
commit: |
There was a problem hiding this comment.
Pull request overview
This PR adds first-class support in SolidStart’s Vite configuration for the conventional server-only and client-only modules, enabling build-time enforcement of server/client module boundaries (as requested in #2162).
Changes:
- Add a Vite pre-enforced plugin that errors when
server-onlyis imported in non-SSR builds orclient-onlyis imported in SSR builds. - Add TypeScript module declarations for
server-onlyandclient-onlyto avoid TS resolution errors for side-effect imports. - Add a changeset to ship the feature as a minor bump for
@solidjs/start.
Reviewed changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| packages/start/src/config/index.ts | Introduces the boundary-enforcement Vite plugin for server-only / client-only. |
| packages/start/env.d.ts | Declares server-only and client-only modules for TypeScript consumers. |
| .changeset/support-server-client-only.md | Publishes the feature as a minor release change. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@lxsmnsyc In that case, the |
|
@YanAnghelp I'm not sure I understood. My point was that the #2207 change has a "server-only" module list, and I feel like instead we can utilize your plugin. Does it work or does the two plugin have to co-exist |
|
@lxsmnsyc I think the same way. We only need to check the module list at the beginning of this plugin. We don't need two plugins. That's why I proposed that this plugin should be moved to a separate file to keep the code concise. |
…a separate plugin Per review feedback, drop the standalone server-only-guard plugin and instead build on the boundary-modules plugin from #2167: the public @solidjs/start/http and @solidjs/start/middleware entries now carry an import "server-only" marker, so pulling them into the client bundle fails at resolve time with an actionable error (#2068). - extract boundary-modules into its own module and extend its errors with fix guidance ("use server" / clientOnly()) - split src/http into a marked public entry re-exporting ./http.ts, so the isomorphic <HttpHeader> (which guards usage behind isServer) can keep importing the helpers without tripping the client-env check - @solidjs/start/config is no longer guarded: it is loaded directly by Node when evaluating vite.config.ts, outside the plugin pipeline, so it cannot carry the marker Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Closes #2162